const Sequelize = require("sequelize");
const { database } = require("./config");
const sequelize = new Sequelize(
  database.name,
  database.username,
  database.password,
  {
    // host: "localhost", // 数据库主机
    // dialect: "mysql", // 数据库类型
    // port: 3306, // 数据库端口号，默认为 3306
    // logging: false, // 是否在控制台打印 SQL 语句，默认为 true
    ...database,
  }
);

// sequelize
//   .sync()
//   .then(() => {
//     console.log("User table created successfully!");
//   })
//   .catch((error) => {
//     console.error("Unable to create table : ", error);
//   });
// 测试连接是否成功
sequelize
  .authenticate()
  .then(() => {
    console.log("Connection has been established successfully.");
  })
  .catch((err) => {
    console.error("Unable to connect to the database:", err);
  });

module.exports = sequelize;
